package com.hspedu.newData.dmsxl.双指针;

import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-28 
 * @Version: 1.0
 */

public class LC1679K和数对的最大数目 {

    public int maxOperations(int[] nums, int k) {

        Arrays.sort(nums);

        int left = 0;
        int right = nums.length-1;

        int count = 0;
        while (left<right){

            if ((nums[left] + nums[right])>k){
                right--;
            } else if ((nums[left] + nums[right])<k) {
                left++;
            }else {
                left++;
                right--;
                count++;
            }
        }
        return count;
    }

    @Test
    public void test() {
        // 测试代码

        int i = maxOperations(new int[]{1, 2, 3, 4}, 5);
        int i1 = maxOperations(new int[]{3,1,3,4,3}, 6);
        System.out.println("111");
    }
}
